True if any item in target equals value, false otherwise (including when target is empty). Nothing in target changes, and no item is taken off the front.
queue_contains(target, value) -> bool| Name | Type |
|---|---|
target | queue |
value | element |
bool
true if any item in target, a queue, equals value, false otherwise (including when target is empty).
It only looks. Nothing is taken off the front and nothing is added to the back, so the order of the queue does not change. It answers yes or no and never says where the value is.
This is the queue's own name for the question list_contains asks a list, stack_contains asks a stack and set_contains asks a set. Each container uses its own name so it is always clear which kind of thing you are asking.
Numbers are equal when they are the same number, and text is equal when every letter is the same.
The search starts at the front and looks at one item after another until it finds a match, so a queue that holds more takes longer, and a search that finds nothing looks at every item. It is handy for "is this one already waiting" checks before you push another.
| You do this | What happens |
|---|---|
| search for a value that is not there | false |
| search for a value that is there more than once | true |
| search an empty queue | false |
| give it a list | refused when checked. A list has its own, list_contains |
/// @type {queue<int>}
var waiting = [];
queue_push(waiting, 4);
queue_push(waiting, 8);
var has8 = queue_contains(waiting, 8); // true
var has99 = queue_contains(waiting, 99); // false
if (not queue_contains(waiting, 12)) {
queue_push(waiting, 12); // only queued if it is not already waiting
}The same left-to-right search list_contains makes (find, the GBA module's own alias for std::find) over the deque the queue is kept in, front to back - O(n) in how many items target holds. It only answers yes or no; it does not say where the value is.